package descentFly.app.tools
{
	import UIFree.uif_component;
	
	import descentFly.app.df_panel;
	import descentFly.data.df_fields;
	
	import flash.display.DisplayObject;
	import flash.geom.Rectangle;
	
	import flashx.textLayout.formats.TextAlign;
	
	public class df_toolDock extends df_panel {
		
		private var _align: String;
		public function df_toolDock(parent:uif_component, a_align: String, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, a_styleClass:Object='panel') {
			_align = a_align;
			super(parent, ax, ay, awidth, aheight, a_styleClass);
		}
		
		override public function addChild(child:DisplayObject):DisplayObject {
			super.addChild(child);
			if (child is df_toolBlock) refreshBlocks();
			return child;
		}
		
		override public function removeChild(child:DisplayObject):DisplayObject {
			super.removeChild(child);
			if (child is df_toolBlock) refreshBlocks();
			return child;
		}
		
		protected function refreshBlocks(): void {
			var v		: int;
			var func	: Function;
			var inner	: Rectangle = getInner();
			var space	: int = getSpace(true);
			switch (_align) {
				case df_dockAlign.LEFT	:  func = function(child: df_toolBlock): void {
														child.y = inner.y;
														child.x = v;
														v += child.width + space;
													}
											v = inner.x;
										break;
				case df_dockAlign.RIGHT	: func = function(child: df_toolBlock): void {
														child.y = inner.y;
														v -= (child.width + space);
														child.x = v;
													}
											v = inner.x + inner.width;
										break;
				case df_dockAlign.TOP	:  func = function(child: df_toolBlock): void {
														child.x = inner.x;
														child.y = v;
														v += child.height + space;
													}
											v = inner.y;
										break;
				case df_dockAlign.BOTTOM: func = function(child: df_toolBlock): void {
														child.x = inner.x;
														v -= (child.height + space);
														child.y = v;
													}
											v = inner.y + inner.height;
										break
			}
			
			forEach(func, df_toolBlock);
		}
	}
}